import request from '@/utils/request'

export function getCouponList(name) {
	let query = new FormData()
	if (name.name != undefined) {
		query.append("name", name.name)
	}
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: `/coupon/list`,
		method: "POST",
		data: query
	})
}

export function getCouponInfo(id) {
	return request({
		url: `/coupon/${id}`,
		method: "GET"
	})
}

export function createCoupon(query) {
	return request({
		url: `/coupon/create`,
		method: "POST",
		data: query
	})
}

export function updateCoupon(id, query) {
	return request({
		url: `/coupon/update/${id}`,
		method: "POST",
		data: query
	})
}

export function deleteCoupon(id) {
	return request({
		url: `/coupon/delete/${id}`,
		method: "POST"
	})
}

export function getHistoryCoupon(name) {
	let query = new FormData()
	query.append("pageNum",name.pageNum);
	if (name.couponName != undefined) {
		query.append("couponName", name.couponName);
	}
	if (name.username != undefined) {
		query.append("username", name.username);
	}
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: `/coupon/history/list`,
		method: "POST",
		data: query
	})
}

export function giveUserCoupon(query) {
	return request({
		url: "/coupon/give",
		method: "POST",
		params: query
	})
}
